package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.SeleArt;
import com.hs.service.SeleArtService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("seleart")
public class SeleArtController {
    @Autowired
    private SeleArtService seleArtService;
    @PostMapping
    public R addseleArt(@RequestBody SeleArt seleArt) {
        Integer i = seleArtService.addseleart(seleArt);
        if (i > 0) {
            return R.ok();
        }else {
            return R.fail("失败");
        }
    }
    @DeleteMapping("{id}")
    public R deleteseleArt(@PathVariable("id") Integer id) {
        Integer i = seleArtService.deleteseleart(id);
        if (i > 0) {
            return R.ok();
        }else {
            return R.fail("失败");
        }
    }
    @PutMapping
    public R updateseleArt(@RequestBody SeleArt seleArt) {
        Integer i = seleArtService.updateseleart(seleArt);
        if (i > 0) {
            return R.ok();
        }else {
            return R.fail("失败");
        }
    }
    @GetMapping("{id}")
    public R getseleArtById(@PathVariable("id") Integer id) {
        SeleArt seleArt = seleArtService.getseleartById(id);
        return R.ok(seleArt);
    }
    @GetMapping("page")
    public R getseleArtByPage(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                              @RequestParam(required = false,defaultValue = "2") Integer pageSize) {
        PageInfo<SeleArt> seleArtPageInfo = seleArtService.getseleartPage(pageNum, pageSize);
        return R.ok(seleArtPageInfo);
    }
    @GetMapping
    public R getseleArtList(SeleArt seleArt) {
        PageInfo<SeleArt> getseleartlist = seleArtService.getseleartlist(seleArt);
        return R.ok(getseleartlist);
    }
}
